package com.drinks.yiniang.adapter.listview;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.drinks.yiniang.R;
import com.drinks.yiniang.entity.goods.RefundGoodsJson;
import com.hansen.library.utils.CommonUtils;

import java.util.List;

/**
 * 退款原因 adapter
 *
 * Created by han on 2019/6/27 0027.
 */

public class RefundReasonAdapter extends BaseAdapter {
    private Context mContext;

    private LayoutInflater inflater;

    private List<RefundGoodsJson.RefundGoodsReason> mList;
    private RefundGoodsJson.RefundGoodsReason mData;

    private Drawable mCheckDrawable;
    private Drawable mNormalDrawable;

    public RefundReasonAdapter(Context mContext, List<RefundGoodsJson.RefundGoodsReason> mList) {
        this.mContext = mContext;
        this.mList = mList;

        inflater = LayoutInflater.from(mContext);

        mCheckDrawable = ContextCompat.getDrawable(mContext, R.mipmap.icon_choose_p);
        mNormalDrawable = ContextCompat.getDrawable(mContext, R.mipmap.icon_choose_n);
    }

    @Override
    public int getCount() {
        return CommonUtils.getListSize(mList);
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder mHolder = null;

        if (convertView == null) {
            mHolder = new ViewHolder();

            convertView = inflater.inflate(R.layout.item_dialog_refund_reason, null);

            mHolder.tv_refund_reason_name = convertView.findViewById(R.id.tv_refund_reason_name);

            convertView.setTag(mHolder);
        } else {
            mHolder = (ViewHolder) convertView.getTag();
        }

        mData = mList.get(position);

        mHolder.tv_refund_reason_name.setText(mData.getName());

        if(mData.isChecked()) {
            mHolder.tv_refund_reason_name.setCompoundDrawablesWithIntrinsicBounds(null, null, mCheckDrawable, null);
        } else {
            mHolder.tv_refund_reason_name.setCompoundDrawablesWithIntrinsicBounds(null, null, mNormalDrawable, null);
        }

        return convertView;
    }

    class ViewHolder {
        //原因
        TextView tv_refund_reason_name;
    }
}
